import React from "react";

export default class FromDemo extends React.Component{
    constructor(){
        super()
        this.state={
            value:""
        }
    }
    render(){
        return (
            <div>
                <h1>表单</h1>
                <form onSubmit={this.onSubmitHandler}>
                    <input type="text" value={this.state.value} onChange={this.onChangeHandler} />
                    <button type="submit">提交</button>
                </form>
            </div>
        )
    }

    onChangeHandler=(e)=>{
        console.log(e.target.value)
        this.setState({
            value:e.target.value
        })
    }
    onSubmitHandler=(e)=>{
        //阻止表单的提交跳转事件
        e.preventDefault();
        console.log(this.state);
    }
}